﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

using Prodma.DataAccess.Models;

namespace Prodma.Panel
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

            //routes.MapRoute(
            //    "Default2",                                              // Route name
            //    "{controller}/{action}/{id}",                           // URL with parameters
            //    new { controller = "Sepet", action = "AddChart", id = "" }  // Parameter defaults
            //);

            routes.MapRoute(
                "SepeteEkle",                                              // Route name
                "{controller}/{action}/{id}/{amount}",                           // URL with parameters
                new { controller = "Sepet", action = "AddChart", id = "", amount = ""}  // Parameter defaults
            );

            //routes.MapRoute(
            //    "SepeteEkleToplu",                                              // Route name
            //    "{controller}/{action}/{id[]}",                           // URL with parameters
            //    new { controller = "Sepet", action = "AddChartTotal", id =""}  // Parameter defaults
            //);

        }

     

        protected void Application_Start()
        {
            Application["loginUserList"] = new List<LoginUser>();
            Application["onlineUsers"] = new Dictionary<int, LoginUser>();
            RegisterRoutes(RouteTable.Routes);
        }

        protected void Application_End()
        {
            
             Application.Lock();
             //Application["loginUserList"] = null;
             //Application["onlineUsers"] = null;
             Application.RemoveAll();
             Application.UnLock();
             
        }

        protected void Session_Start()
        {
            
           

        }

        protected void Session_End() 
        {
            LoginUser lu = (LoginUser)Session["loginUser"];
            ((Dictionary<int, LoginUser>)Application["onlineUsers"]).Remove(lu.Id);
            ((List<LoginUser>)Application["loginUserList"]).Remove(lu);
            lu = null;        
        }

    }
}